#ifndef KLINEWIDGET_H
#define KLINEWIDGET_H

#include <QOpenGLWidget>
#include <QOpenGLFunctions>
#include <QOpenGLShaderProgram>
#include <QOpenGLBuffer>
#include <QOpenGLVertexArrayObject>
#include "klinedata.h"

class KLineWidget : public QOpenGLWidget, protected QOpenGLFunctions {
    Q_OBJECT

public:
    explicit KLineWidget(QWidget *parent = nullptr);
    ~KLineWidget();

    void setKLineData(const QVector<KLineData> &data);

protected:
    void initializeGL() override;
    void paintGL() override;
    void resizeGL(int width, int height) override;

private:
    void setupShaders();
    void setupBuffers();

    QOpenGLShaderProgram *m_program;
    QOpenGLBuffer m_vbo;
    QOpenGLBuffer m_ibo;
    QOpenGLVertexArrayObject m_vao;

    QVector<KLineData> m_klineData;
    int m_width;
    int m_height;

    bool m_initialized; // 标志位，跟踪 OpenGL 是否已初始化
};

#endif // KLINEWIDGET_H